package com.example.demo.common;


import com.example.demo.entity.Userinfo;
import com.example.demo.entity.vo.UserinfoVO;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 *  当前登录用户的相关操作.
 */
public class UserSessionUtils {
    /**
     * 拿到用户登录对象
     */
    public static Userinfo getUser(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if (session != null && session.getAttribute(AppVariable.USER_SESSION_KEY) != null) {
            // 已经登录
            return (Userinfo)session.getAttribute(AppVariable.USER_SESSION_KEY);
        }
        // 未登录 返回一个 null
        return null;
    }

    public static String getImgCode(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if (session != null && session.getAttribute(AppVariable.LOGIN_CHECK_CODE) != null) {
            return (String) session.getAttribute(AppVariable.LOGIN_CHECK_CODE);
        }
        return null;
    }
}
